﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.Windows.Forms;

namespace FigureDraw
{
    public abstract class CommonShape
    {
        protected int R;
        protected int G;
        protected int B;
        protected int LineWidth;

        public Point BeginPoint { set; get; }
        public Point EndPoint { set; get; }

        protected String strInfor = "";
        protected RichTextBox rtbInfor;

        protected Infor infor;


        private StorageDevice storageDevice;

        public StorageDevice StorageDevice
        {
            get { return storageDevice; }
            set { storageDevice = value; }
        }
        
        public CommonShape(StorageDevice sd)
        {
            this.storageDevice = sd;
            this.rtbInfor = new RichTextBox();
            this.strInfor = "";
            this.rtbInfor.TextChanged += new EventHandler(rtbInfor_TextChanged);
            this.infor = new Infor();
            
        }

        public CommonShape(StorageDevice sd, Infor infor)
        {
            this.StorageDevice = sd;
            this.rtbInfor = new RichTextBox();
            this.strInfor = infor.strInfor;
            this.rtbInfor.TextChanged += new EventHandler(rtbInfor_TextChanged);
            this.infor = new Infor();
            this.BeginPoint = infor.startPoint;
            this.EndPoint = infor.endPoint;
            this.R = infor.color.R;
            this.G = infor.color.G;
            this.B = infor.color.B;
            this.LineWidth = this.infor.LineSize;
            this.KhoiTaoTruocKhiVe();
            //this.infor.color = Color.FromArgb(this.R, this.G, this.B);
        }

        public CommonShape() { }

        public abstract void DrawToDevice(Form form);
        public void KhoiTaoTruocKhiVe()
        {
            this.StorageDevice.setColor(this.R, this.G, this.B);
            this.StorageDevice.setLineWidth(this.LineWidth);
        }


        private void rtbInfor_TextChanged(object sender, EventArgs e)
        {
            this.strInfor = this.rtbInfor.Text;
        }

        public virtual CommonShape Clone(DiagramFactory factory, Infor infor)
        {
            return this;
        }

        public virtual StorageDevice GetStorageDevice()
        {
            return this.StorageDevice;
        }

        public Infor GetInfor()
        {
            this.infor.startPoint = this.BeginPoint;
            this.infor.endPoint = this.EndPoint;
            this.infor.strInfor = this.strInfor;
            this.infor.color = Color.FromArgb(this.R, this.G, this.B);
            this.infor.LineSize = this.LineWidth;
            return this.infor;
        }


        public void setColor(int r, int g, int b)
        {
            this.R = r;
            this.G = g;
            this.B = b; 
        }
        public void setLineWidth(int lw)
        {
            this.LineWidth = lw;
        }

        public int getRColor()
        {
            return this.R;
        }
        public int getGColor()
        {
            return this.G;
        }
        public int getBColor()
        {
            return this.B;
        }
        public int getLineWidth()
        {
            return this.LineWidth;
        }







        public void Clear()
        {
            this.rtbInfor.Visible = false;
            this.storageDevice.ClearAll();
        }
    }
}
